
package com.chy.utilsdemo.validator;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.Set;

/**
 * 功能： validator 校验
 *
 * ──────────────────────────────────────────
 *   version  变更日期    修改人    修改说明
 * ------------------------------------------
 *   V1.0.0   2021/11/3     CHY     初版
 * ──────────────────────────────────────────
 * @author chy
 */
@RestController
@RequestMapping("/validator")
@Api("检验中心")
public class ValidatorTestController {

    @Resource
    private Validator validator;

    @GetMapping("/test")
    @ApiOperation(value = "实体类校验", httpMethod = "GET", notes = "实体类校验")
    public String validator() {
        User user = new User();
        user.setName("00000000000000000000000000000");
        user.setMobile("4561253");
        user.setIdCard("11111111111111111111111111111111111111");
        Set<ConstraintViolation<User>> errors = validator.validate(user);
        System.out.println(errors);
        return errors.toString();
    }
}
